if not SYSPATH then return end

local M  = {}
local model      = app.gamesUse("model")
local hall_model = app.model("hall")		--大厅数据

--消息枚举
M.State = {
    start_Start         = 401,      --游戏开始
    start_Zhuang        = 402,      --进入抢庄模式
	start_Outcard       = 403,      --进入出牌模式
	start_Double        = 404,      --进入加倍模式
	start_Wait          = 405,      --进入等待模式
	start_Bit           = 406,      --进入下注模式
	start_Brand         = 407,      --进入亮牌模式
	start_Sign_Resule   = 408,      --进入小结算模式

    Licensing     = 101,      --发牌
    Rob_zhuang    = 102,      --抢庄
	Get_cards     = 103,      --要牌
    Double        = 104,      --加倍
    Bit           = 106,      --下注
	Look_card     = 107,      --看牌
	Discard_card  = 108,      --弃牌
	Call          = 109,      --跟注
	Bright_brand  = 110,      --亮牌
	Start_compcard= 111,      --开始比牌
	End_compcard  = 112,      --比牌
	Tobrand_card  = 113,      --要牌
	Out_card      = 114,      --出牌
	Not_Out_card  = 115,      --不出
	Bu_hui        = 201,      --补花
	Eat_card      = 202,      --吃牌
	Toucha_card   = 203,      --碰牌
	Carry_card    = 204,      --扛牌
	Hu_card       = 205,      --胡牌
	Carry_ha      = 206,      --扛上花
	Rob_to_carry  = 207,      --抢扛胡
}

--请求子游戏配置
function M:onPlayerInfoAction(params)
 	local PlayerInfoMap = model.PlayerInfoMap.get()
	if PlayerInfoMap:getpair(params) then                     --如果有从本地取
		MVC.facade:send(Event.EVENT_JCXJ_PLAYER_REF,params)  
		return
	end
    HttpMgr:onPlayerInfo(params,function(info)
 		local uid = info.data.Data.Uid
 		info.data.Data.FaceUrl = crypto.decodeBase64(info.data.Data.FaceUrl)   -- 头像解密
		PlayerInfoMap:insert(uid,info.data.Data)
		MVC.facade:send(Event.EVENT_JCXJ_PLAYER_REF,uid)  
    end)
end

--开始游戏
function M:onGameStartAction()
	print("--------------------发送开始游戏--------------------")
	local data = {msgID = MSG_APPLY_START_GAME,package = {Uid = hall_model.Uid.get()}}
	print("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS")
	dump(data)
    MVC.sendData(data)
end
-- --开始游戏
-- function M:onGameStartAction()
-- 	print("--------------------发送开始游戏--------------------")
--     local data = {msgID = MSG_APPLY_START_GAME,package = {Uid = hall_model.Uid.get()}}
--     MVC.sendData(data)
-- end

--玩家操作状态
function M:sendAction(_state,param) --_state,param
    local sendData = {
        msgID = MSG_TABLE_INFO,   
        package = {
            state = _state,
				data = param and {msg = param,Uid = hall_model.Uid.get()} or {Uid = hall_model.Uid.get()} 
		}
	}
	
	print("判断发送格式是否正确----------------------") --assert(nil)
	dump(sendData)
    MVC.sendData(sendData)
end
--玩家操作状态 比牌或看牌
function M:SendAction(_state,param) --_state,param
    local sendData = {
        msgID = MSG_TABLE_INFO,   
        package = {
            state = _state,
				--data = param and {msg = param,Uid = hall_model.Uid.get()} or {Uid = hall_model.Uid.get()}
				data = param
		}
	}
	
	print("判断发送格式是否正确----------------------") --assert(nil)
	dump(sendData)
    MVC.sendData(sendData)
end

--玩家操作状态 下注或跟注
function M:sendActionNum(_state,param) --_state,param
    local sendData = {
        msgID = MSG_TABLE_INFO,   
        package = {
            state = _state,
				data = param and {bet = param,Uid = hall_model.Uid.get()} or {Uid = hall_model.Uid.get()} 
		}
	}
	
	print("判断发送格式是否正确----------------------") --assert(nil)
	dump(sendData)
    MVC.sendData(sendData)
end


--解散
function M:choiceDismiss(param)
    local sendData = {
        msgID = MSG_DISSOLUTION_ACTION,
        package = {param}
    }
    MVC.sendData(sendData)
end

--准备
function M:onGameReady(uid)
	local data = {msgID = MSG_APPLY_READY,package = {Uid = hall_model.Uid.get()}}
	--local data = {msgID = MSG_APPLY_READY,package = {Uid = uid}}
	print("准备-------------------------------")
	dump(data)
	MVC.sendData(data)
end
--聊天
function M:onChat(value,chr)
	print("是否收到表情消息----------------",value)
    local sendData = {
        msgID = MSG_CHAT,
        package = {
			Uid = hall_model.Uid.get(),
			roomid = hall_model.TableID.get(),
			value = value,
			name = chr,
        }
	}
	dump(sendData)
    MVC.sendData(sendData)
end

--离开房间
function M:onRoomLeaveAction()
    local data = {
    msgID = MSG_LEAVE_ROOM,
    package = {
        Uid = app.model("hall").Uid.get(),
        TableID = model.roomData._roomid
        }
    }
    MVC.sendData(data)
end

return M